home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 424_01 / ed_157 / smaller_win.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-10  |  3.3 KB  |  129 lines

  1. /*
  2.  * Copyright (C) 1992 by Rush Record (rhr@clio.rice.edu)
  3.  * 
  4.  * This file is part of ED.
  5.  * 
  6.  * ED is free software; you can redistribute it and/or modify it under the terms
  7.  * of the GNU General Public License as published by the Free Software Foundation.
  8.  * 
  9.  * ED is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  10.  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  11.  * PARTICULAR PURPOSE.  See the GNU General Public License for more details.
  12.  * 
  13.  * You should have received a copy of the GNU General Public License along with ED
  14.  * (see the file COPYING).  If not, write to the Free Software Foundation, 675
  15.  * Mass Ave, Cambridge, MA 02139, USA.
  16.  */
  17. #include "opsys.h"
  18.  
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <string.h>
  22.  
  23. #include "rec.h"
  24. #include "window.h"
  25. #include "ed_dec.h"
  26. #include "handy.h"
  27.  
  28. /******************************************************************************\
  29. |Routine: smaller_window
  30. |Callby: command
  31. |Purpose: Decreases the size of a window.
  32. |Arguments:
  33. |    decrease - the number of lines to subtract from the window.
  34. \******************************************************************************/
  35. void smaller_window(decrease)
  36. Int decrease;
  37. {
  38.     Int i,j,topfree,botfree;
  39.     rec_ptr r;
  40.     
  41.     if(NWINDOWS == 1)
  42.         return;
  43. /* don't do anything if the window is 3 lines */
  44.     if((i = BOTROW - TOPROW + 1) <= 3)
  45.         return;
  46. /* don't free so many lines we go below three lines for this window */
  47.     if(i - decrease < 3)
  48.         decrease = i - 3;
  49. /* handle different cases */
  50.     if(!CURWINDOW)    /* must shrink at bottom */
  51.     {
  52.         topfree = 0;
  53.         botfree = decrease;
  54.     }
  55.     else if(CURWINDOW == NWINDOWS - 1)    /* must shrink at top */
  56.     {
  57.         topfree = decrease;
  58.         botfree = 0;
  59.     }
  60.     else    /* split shrinkage equally */
  61.     {
  62.         topfree = decrease >> 1;
  63.         botfree = decrease - topfree;
  64.     }
  65. /* shrink the window */
  66.     save_window();
  67.     if(topfree)
  68.     {
  69.         TOPROW = WINDOW[CURWINDOW].toprow += topfree;
  70.         WINDOW[i = CURWINDOW - 1].botrow += topfree;
  71.         new_botrec(i);
  72.         calc_limits(WINDOW[i].toprow,WINDOW[i].botrow,&WINDOW[i].toplim,&WINDOW[i].botlim);
  73.         marge(1,NROW);
  74.         ref_window(i);
  75.         if(!WINDOW[i].botrec)
  76.         {
  77.             j = CURWINDOW;
  78.             set_window(j - 1);
  79.             for(i = 0,r = TOPREC;r != BASE;r = r->next,i++);
  80.             CURROW += scroll_down(BOTROW - TOPROW - i);
  81.             save_window();
  82.             set_window(j);
  83.         }
  84.     }
  85.     if(botfree)
  86.     {
  87.         BOTROW = WINDOW[CURWINDOW].botrow -= botfree;
  88.         WINDOW[i = CURWINDOW + 1].toprow -= botfree;
  89.         calc_limits(WINDOW[i].toprow,WINDOW[i].botrow,&WINDOW[i].toplim,&WINDOW[i].botlim);
  90.         new_botrec(i);
  91.         for(r = WINDOW[i].toprec,j = WINDOW[i].toprow;j != WINDOW[i].botrow;r = r->next,j++)
  92.         {
  93.             if(r == WINDOW[i].currec)
  94.             {
  95.                 WINDOW[i].currow = j;
  96.                 break;
  97.             }
  98.             if(r == WINDOW[i].base)
  99.                 break;
  100.         }
  101.         marge(1,NROW);
  102.         ref_window(i);
  103.         if(!WINDOW[i].botrec)
  104.         {
  105.             j = CURWINDOW;
  106.             set_window(j + 1);
  107.             for(i = 0,r = TOPREC;r != BASE;r = r->next,i++);
  108.             CURROW += scroll_down(BOTROW - TOPROW - i);
  109.             save_window();
  110.             set_window(j);
  111.         }
  112.     }
  113.     calc_limits(TOPROW,BOTROW,&TOPLIM,&BOTLIM);
  114.     CURROW = i = (TOPLIM + BOTLIM) >> 1;    /* put CURREC midway between limits */
  115.     for(r = CURREC;r->prev != BASE && i != TOPROW;i--,r = r->prev);
  116.     TOPREC = r;
  117.     CURROW -= (i - TOPROW);
  118.     save_window();
  119.     new_botrec(CURWINDOW);
  120.     set_window(CURWINDOW);
  121.     ref_window(CURWINDOW);
  122.     if(!BOTREC)
  123.     {
  124.         for(i = 0,r = TOPREC;r != BASE;r = r->next,i++);
  125.         CURROW += scroll_down(BOTROW - TOPROW - i);
  126.     }
  127. }
  128.  
  129.